package com.lyshop.jinxiang.activitys;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.lyshop.jinxiang.R;
import com.lyshop.jinxiang.application.MyApplication;
import com.lyshop.jinxiang.base.BaseActivity;
import com.lyshop.jinxiang.bean.RetailOrderBean;
import com.lyshop.jinxiang.net.ActionCallbackListener;
import com.lyshop.jinxiang.utils.ToastUtil;
import com.lyshop.jinxiang.view.MoneyTextView;

public class RetailOrderInfoActivity extends BaseActivity {
    private  RetailOrderBean bean;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int setContentView() {
        return R.layout.activity_retail_order_info;
    }

    @Override
    protected void findViews() {
        bean = (RetailOrderBean) getIntent().getSerializableExtra("RetailOrderBean");

        TextView tv_order_no = $(R.id.tv_order_no);
        TextView tv_goods_name = $(R.id.tv_goods_name);
        TextView tv_order_status = $(R.id.tv_order_status);
        ImageView iv_goods = $(R.id.iv_goods);
        MoneyTextView mtv_goods_money = $(R.id.mtv_goods_money);
        TextView tv_goods_number = $(R.id.tv_goods_number);
        TextView tv_describe = $(R.id.tv_describe);
        Button bt_submit = $(R.id.bt_submit);
        TextView tv_user_info = $(R.id.tv_user_info);
        tv_user_info.setText(bean.getAddress_user_name()+"  "+bean.getMobile());
        TextView tv_user_address = $(R.id.tv_user_address);
        tv_user_address.setText(bean.getRegion()+bean.getAddress());

        String orderNo = "订单编号：" + bean.getOrder_id();
        String number = "x" + bean.getAmount();
        String proName = bean.getName();
        String money = String.valueOf(bean.getPrice());
        String describe = "共" + bean.getAmount() + "件 实付￥" + bean.getMoney_sum();

        Glide.with(mContext).load(bean.getGoods_img()).into(iv_goods);

        tv_order_no.setText(orderNo);
        tv_goods_name.setText(proName);
        tv_goods_number.setText(number);
        mtv_goods_money.setText(money);
        tv_describe.setText(describe);

        bt_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(bean.getStatus() ==1){
                    ToastUtil.showToast(mContext,"请联系客服");
                    return;
                } else if (bean.getStatus() ==2) {
                    onConfirm(bean.getOrder_id());
                }
            }
        });

        bt_submit.setVisibility(View.GONE);
        switch (bean.getStatus()) {
            case 1:
                //待发货
                tv_order_status.setText("待发货");
                tv_order_status.setTextColor(mContext.getResources().getColor(R.color.color_477ae5));
                bt_submit.setVisibility(View.VISIBLE);
                bt_submit.setText("取消订单");
                break;
            case 2:
                //提货中
                tv_order_status.setText("待收货");
                tv_order_status.setTextColor(mContext.getResources().getColor(R.color.color_477ae5));
                bt_submit.setVisibility(View.VISIBLE);
                bt_submit.setText("确认收货");
                break;
            case 3:
                //成功
                tv_order_status.setTextColor(mContext.getResources().getColor(R.color.color_gray_02));
                tv_order_status.setText("已完成");
                bt_submit.setVisibility(View.GONE);
                break;
            case 9:
                //失败
                tv_order_status.setTextColor(mContext.getResources().getColor(R.color.color_gray_02));
                tv_order_status.setText("已失败");
                bt_submit.setVisibility(View.GONE);
                break;
        }
    }
    public void onConfirm(String order_id) {
        mAppAction = MyApplication.getApplication().getAppAction();
        mAppAction.confirmOrder(order_id, new ActionCallbackListener<Void>() {
            @Override
            public void onSuccess(Void data) {
                ToastUtil.showToast(mContext,"操作成功");
                finish();
            }

            @Override
            public void onFailure(String errorCode, String message) {
                ToastUtil.showToast(mContext,message);
            }
        });
    }
    @Override
    protected void setListeners() {

    }
}
